<?php
include('function.php');
$file = $argv[1];
$content = file_get_contents($file);
$jiance = preg_match('/文件已解密一次/ims', $content);
if (!empty($jiance)) {
    exit('文件已解密过');
}
$topbin = preg_split('/unset\(\$\w+\);/ims', $content)[0];
// $topbin = preg_split('/\$GLOBALS\[.+?\]=explode\(.+?\);/i', $content)[0];
// $topbin = preg_split_end('/\$GLOBALS\[.+?\]=explode\(.+?\);/i',$content);
// $topbin = preg_split('/\$GLOBALS\[.+?\]=explode\(.+?\);/i', $content);
// $topbin = array_pop($topbin);
// $topbin = $topbin[5];
// print_r($topbin);
// exit;
$fopen = fopen('topbin.php', 'w');
fwrite($fopen, $topbin);
fclose($fopen);
// exit;
include('topbin.php');
unlink('topbin.php');
$shujv = array();
$data = preg_split('/unset\(\$\w+\);/ims', $content);
// 首先分割开关键词转为数组
for ($i = 0; $i < count($data); $i++) {
    $fenduan = $data[$i];
    // print_r($fenduan);
    // exit;
    // 搜索的变量名称
    if (preg_match('/call_user_func_array\("pack",.?array\(&\$\w+,.?&(\$\w+)\)\);/ims', $fenduan, $bianliang)) {
        $bianliang = $bianliang[1];
        // 搜索变量内容
        preg_match('/\\' . $bianliang . '.?=(\$.{7}\[\w+\]\[\w+\]);/ims', $fenduan, $blcontent);
        $blcontent = $blcontent[1];
        if (isset($blcontent)) {
            $rand = rand() . '.php';
            $txt = '<?php $str = pack(\'H*\',' . $blcontent . ')?>';
            wj_w($rand, $txt);
            include($rand);
            unlink($rand);
            $zz = '/\\' . $bianliang . '=.?\$.{7}\[\w+\]\[\w+\];/ims';
            $zifu = preg_filter($zz, '', $fenduan);
            $zz = '/call_user_func_array\("pack",array\(&\$\w+,&\$\w+\)\)/ims';
            $fenduan = preg_filter($zz, '\'' . zy($str) . '\'', $zifu);
        }
    }
    $shujv[] = $fenduan;
}
$cont = implode('', $shujv);
$content = youhua('echo', $cont, 150);
$content = hanshu($content);
$content = bin_h($content);
$content = array_is($content);
$content = md_5($content);
$content = packs($content);
$content = echo_conf($content);
for ($i = 0; $i < 20; $i++) {
    $content = go_to1($content);
}
$content = go_to2($content);
$content = go_to3($content);
$content = go_to4($content);
$content = go_to4($content);
$content = go_to4($content);
// $content = format_code($content);
// print_r($content);
// exit;


$content_data =  $content;
$content = format_code($content);
$pathinfo = pathinfo($file);
$file = $pathinfo['filename'] . '-decode.' . $pathinfo['extension'];
if ($content) {
    $wenjian = wj_w($file, $content . "\n" . '//文件已解密一次');
    if ($wenjian) {
        echo '解密成功';
    }
} else {
    echo '格式化代码失败';
    $wenjian = wj_w($file, $content_data . "\n" . '//文件已解密一次');
    if ($wenjian) {
        echo '<br>解密成功';
    }
}
